package com.unbox.admin.controller;

import com.unbox.admin.entity.Setting;
import com.unbox.admin.fegin.SettingFegin;
import com.unbox.admin.service.ISettingService;
import com.unbox.common.annotation.Log;
import com.unbox.common.response.UnboxResponse;
import com.unbox.common.table.UnBoxPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 * < 系统设置业务Controller
 * </p>
 *
 * @author 王振宇
 * @since 2021-04-23
 */
@Api(tags = " 系统设置管理api")
@RestController
public class SettingController implements SettingFegin {

    @Autowired
    ISettingService settingService;

    /**
     * 分页查询
     * @param setting
     * @return
     */
    @ApiOperation(value = "分页查询列表")
    @Override
    public UnboxResponse<UnBoxPage> getPageList(Setting setting, Integer pageNo, Integer pageSize) {
        UnBoxPage page = settingService.getPageList(setting,pageNo, pageSize);
        return new UnboxResponse<>(page);
    }

    /**
     * 详情
     * @param setting
     * @return
     */
    @ApiOperation(value = "查询明细")
    @Log(name = "系统设置明细")
    @Override
    public UnboxResponse<Setting> info(Setting setting) {
        Setting settingVo = settingService.get(setting);
        return new UnboxResponse<>(settingVo);
    }

    /**
     * 通过id数据查询数据
     * @param ids
     * @return
     */
    @ApiOperation(value = "通过ids进行in查询")
    @Override
    public UnboxResponse<List<Setting>> idsSettings(List<Integer> ids) {
        List<Setting> settings = settingService.getIdsList(ids);
        return new UnboxResponse<>(settings);
    }

    /**
     * 保存数据
     * @param setting
     * @return
     */
    @ApiOperation(value = "保存数据")
    @Override
    public UnboxResponse<Boolean> save(Setting setting) {
        Boolean flg = settingService.save(setting);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量添加
     * @param settings
     * @return
     */
    @ApiOperation(value = "批量保存数据")
    @Override
    public UnboxResponse<Boolean> batchSave(List<Setting> settings) {
        Boolean flg = settingService.saveBatch(settings);
        return new UnboxResponse<>(flg);
    }

    /**
     * 修改数据
     * @param setting
     * @return
     */
    @ApiOperation(value = "修改数据")
    @Log(name = "系统设置变更")
    @Override
    public UnboxResponse<Boolean> update(Setting setting) {
        Boolean flg = settingService.update(setting);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量修改
     * @param settings
     * @return
     */
    @ApiOperation(value = "批量修改数据")
    @Override
    public UnboxResponse<Boolean> batchUpdate(List<Setting> settings) {
        Boolean flg = settingService.updateBatchById(settings);
        return new UnboxResponse<>(flg);
    }

    /**
     * 删除数据
     * @param setting
     * @return
     */
    @ApiOperation(value = "删除数据")
    @Override
    public UnboxResponse<Boolean> delete(Setting setting) {
        Boolean flg = settingService.remove(setting);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除")
    @Override
    public UnboxResponse<Boolean> deleteBatch(List<Integer> ids) {
        Boolean flg = settingService.removeByIds(ids);
        return new UnboxResponse<>(flg);
    }
}

